/** FASSIT (Forms of Selective Attention in Intelligent Transportation Systems)
 * Computational Creativity and Digital Media
 * Cognitive and Media Systems Group
 * Centre for Informatics and Systems of the University of Coimbra (CISUC)
 *
 * Copyright (c) 2010-2013 University of Coimbra, Portugal
 * All rights reserved.
 */
package poi.SurpriseCalculator;

import java.util.HashMap;

import masterAgent.DBmanager.DBConnection;
import poi.Info.POI;
import poi.Info.Price;
import poi.Surprise.SurprisePrice;
import agent.Context.Goal;

/**
 * This class is used to calculate the Master agent Surprise for the parameter
 * Price
 * 
 * @author Hernani Costa
 * @version 0.1 date: 28/11/2012
 */
public class SurpriseCalculatorForPrice {
	HashMap<Integer, SurprisePrice> poiSurprisePrice;

	/**
	 * ------------------------------------------------------------------------
	 * Constructor class
	 * ------------------------------------------------------------------------
	 * 
	 * @param pois
	 *            - list with the POIs that we intend to calculate the surprise
	 */
	public SurpriseCalculatorForPrice(HashMap<Integer,POI> pois) {
		poiSurprisePrice = new HashMap<Integer, SurprisePrice>();
		calculates_Surprise_Knowledge_About_Price(pois);
	}

	/**
	 * Calculates the Surprise for the parameter Price
	 * 
	 * @param pois
	 *            - list with the POIs that we intend to calculate the surprise
	 */
	private void calculates_Surprise_Knowledge_About_Price(HashMap<Integer,POI> pois) {
		SurprisePrice surprisePrice = null;
		for (POI poi : pois.values()) {
			Price price = poi.getPrice();
			//System.out.println("price: " + price.toString());
			
			if (!price.hasPrice()){
				surprisePrice = new SurprisePrice(0.33, 0.33, 0.33);
			} else if (price.getAveragePrice().equals("Cheap")) {
				surprisePrice = new SurprisePrice(1.0, 0.0, 0.0);
			} else if (price.getAveragePrice().equals("Average")) {
				surprisePrice = new SurprisePrice(0.0, 1.0, 0.0);
			} else if (price.getAveragePrice().equals("Expensive")) {
				surprisePrice = new SurprisePrice(0.0, 0.0, 1.0);
			}
			poiSurprisePrice.put(poi.getPoiID(), surprisePrice);
		}
	}

	// ------------------------------------------------------------------------
	// ------------------------GETs and SETs-----------------------------------
	// ------------------------------------------------------------------------

	public HashMap<Integer, SurprisePrice> getPoiSurprisePrice() {
		return poiSurprisePrice;
	}

	/**
	 * 
	 * @return a String with the Surprise values for the parameter Schedule, for
	 *         all POIs
	 */
	public String to_String() {
		String info = "";
		for (int poiID : poiSurprisePrice.keySet()) {
			info += "poiID: " + poiID + "\n\t"
					+ poiSurprisePrice.get(poiID).to_String() + "\n";
		}
		return info;
	}

	/**
	 * ------------------------------------------------------------------------
	 * Only for debug purpose
	 * ------------------------------------------------------------------------
	 */
	public static void main(String args[]) {
		// DBManager manager = new DBManager();
		DBConnection connector = new DBConnection();

		POI poi = connector.getPOI(1507669);
		// System.err.println("O pesquisado\n" + poi.to_String() + "\n\n");

		HashMap<Integer,POI> pois = connector.getPOIsNear(poi.getLocation(),
				200, new Goal().getDinner());
		// for (POI p : pois) {
		// System.err.println(p.to_String());
		// }

		SurpriseCalculatorForPrice m = new SurpriseCalculatorForPrice(pois);
		System.out.println(m.to_String());
	}

}
